<template>
  <div class="warp">
    <div class="warp_auto">
      <div class="warp_top">
        <div class="jiansuo-box">
          <span class="label">操作类型：</span>
          <el-select
            v-model="caozuo"
            placeholder="请选择"
            clearable
            class="input"
          >
            <el-option
              v-for="item in options"
              :key="item.id"
              :label="item.label"
              :value="item.value"
            />
          </el-select>
        </div>
        <div class="jiansuo-box">
          <span class="label">操作位置：</span>
          <el-select
            v-model="weizhi"
            placeholder="请选择"
            clearable
            class="input"
          >
            <el-option
              v-for="item in list"
              :key="item"
              :label="item"
              :value="item"
            />
          </el-select>
        </div>
        <div class="jiansuo-box">
          <span class="label">操作人：</span>
          <el-select v-model="ren" placeholder="请选择" clearable class="input">
            <el-option
              v-for="item in listarr"
              :key="item.id"
              :label="item.user_name"
              :value="item.login_name"
            />
          </el-select>
        </div>
        <div class="jiansuo-box">
          <span class="label">操作时间：</span>
          <el-date-picker
            v-model="time_"
            type="daterange"
            align="right"
            format="yyyy-MM-dd"
            value-format="yyyy-MM-dd"
            unlink-panels
            range-separator="至"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
            :picker-options="pickerOptions"
          />
        </div>
        <div class="jiansuo-box">
          <el-button
            type="primary"
            icon="el-icon-search"
            class="btn"
            @click="btn"
          >检索</el-button>
        </div>
      </div>

      <el-card>
        <el-table
          :data="data"
          style="width: 100%"
          height="490"
          stripe
          :header-cell-style="{ background: '#d2e0f9', color: '#606266' }"
        >
          <el-table-column type="expand">
            <template slot-scope="props">
              <el-form label-position="left" inline class="demo-table-expand">
                <span>{{ props.row.content }}</span>
              </el-form>
            </template>
          </el-table-column>
          <el-table-column label="序号" type="index" width="50" align="center" />
          <el-table-column label="操作时间" prop="operate_time" min-width="48%" align="center" />
          <el-table-column label="操作人" prop="operator_code" min-width="30%" align="center" />
          <el-table-column label="操作位置" prop="menu_code" min-width="36%" align="center" />
          <el-table-column label="子位置" prop="operate_type" min-width="30%" align="center" />
          <el-table-column label="病人姓名" prop="name" min-width="36%" align="center" />
          <el-table-column label="执行操作" prop="operate_type" min-width="30%" align="center" />
        </el-table>
        <div class="paging">
          <el-pagination
            :current-page="start"
            :page-size="PageSize"
            layout="total, sizes, prev, pager, next, jumper"
            :pager-count="5"
            :total="totalCount"
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
          />
        </div>
      </el-card>
    </div>
  </div>
</template>
<script>
import axios from 'axios'
import { sysQuerySystemProperties, logGetList, usergetList } from '@/api/table'
export default {
  components: {},
  data() {
    return {
      caozuo: '',
      weizhi: '',
      ren: '',
      time_: '',
      value2: '',
      start: 1, // 默认显示第几页
      totalCount: 0, // 总条数，根据接口获取数据长度(注意：这里不能为空)
      pgeSizes: [10, 20, 30, 40], // 个数选择器（可修改）
      PageSize: 10, // 默认每页显示的条数（可修改）
      options: [
        {
          id: '0',
          value: '新增',
          label: '新增'
        },
        {
          id: '1',
          value: '修改',
          label: '修改'
        },
        {
          id: '2',
          value: '删除',
          label: '删除'
        },
        {
          id: '3',
          value: '同步',
          label: '同步'
        },
        {
          id: '4',
          value: '确认',
          label: '确认'
        }
      ],
      pickerOptions: {
        shortcuts: [
          {
            text: '最近一周',
            onClick(picker) {
              const end = new Date()
              const start = new Date()
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 7)
              picker.$emit('pick', [start, end])
            }
          },
          {
            text: '最近一个月',
            onClick(picker) {
              const end = new Date()
              const start = new Date()
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 30)
              picker.$emit('pick', [start, end])
            }
          },
          {
            text: '最近三个月',
            onClick(picker) {
              const end = new Date()
              const start = new Date()
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 90)
              picker.$emit('pick', [start, end])
            }
          }
        ]
      },
      list: [],
      data: [],
      listarr: []
    }
  },
  created() {
    const start = new Date()
    const end = new Date()
    this.time_ = [start, end]
  },
  mounted() {
    sysQuerySystemProperties({ sysKey: '操作位置' }).then((res) => {
      this.list = res.data
    })
    usergetList({ status: 1 }).then((res) => {
      this.listarr = res.data
    })
    this.logQueryList(this.PageSize, this.start)
  },
  methods: {
    logQueryList(n1, n2) {
      logGetList({
        startTime: this.time_[0],
        endTime: this.time_[1],
        size: n1,
        start: n2
      }).then((res) => {
        this.data = res.data
        this.totalCount = res.totalCount
      })
    },
    btn() {
      this.start=1;
      logGetList({
        operateType: this.caozuo === '' ? null : this.caozuo,
        menuCode: this.weizhi === '' ? null : this.weizhi,
        operatorCode: this.ren === '' ? null : this.ren,
        startTime: this.time_[0],
        endTime: this.time_[1],
        size: this.PageSize,
        start: this.start
      }).then((res) => {
        this.data = res.data
        this.totalCount = res.totalCount
      })
    },
    // 每页显示的条数
    handleSizeChange(val) {
      // 改变每页显示的条数
      this.PageSize = val
      // 点击每页显示的条数时，显示第一页
      this.logQueryList(val, 1)
      // 注意：在改变每页显示的条数时，要将页码显示到第一页
      this.start = 1
    },
    // 显示第几页
    handleCurrentChange(val) {
      // 改变默认的页数
      this.start = val
      // 切换页码时，要获取每页显示的条数
      this.logQueryList(this.PageSize, this.start)
    }
  }
}
</script>
